/*
 * @Author: LiJia
 * @Date: 2021-03-10 13:08:34
 * @LastEditTime: 2021-04-06 13:46:18
 * @LastEditors: LiJia
 * @Description: Description
 * @FilePath: \class-manage-system\miniprogram\pages\mine\children\teacher-test\teacher-test.ts
 */
Page({

  // 页面的初始数据
  data: {
    clsUserInfo: {},
    testTable: [],
    hasMoreTestInfo: false
  },

  // 生命周期函数--监听页面加载
  onLoad() {
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('clsUserInfo', (req) => {
      this.setData({
        clsUserInfo: req.data
      })
    })
    this.getTestTable()
  },

  // 生命周期函数--监听页面初次渲染完成
  onReady() {},

  // 生命周期函数--监听页面显示
  onShow() {},

  // 生命周期函数--监听页面隐藏
  onHide() {},

  // 生命周期函数--监听页面卸载
  onUnload() {},

  // 页面相关事件处理函数--监听用户下拉动作
  onPullDownRefresh() {},

  // 页面上拉触底事件的处理函数
  onReachBottom() {},

  // 用户点击右上角分享
  onShareAppMessage() {
    return {};
  },

  // ==================== 用户自定义方法 start =================== //
  getTestTable() {
    let that = this
    const apiUrl = wx.getStorageSync('apiUrl')
    debugger
    wx.request({
      url: apiUrl + '/test-select',
      data: {
        id: (that.data.clsUserInfo as any).id || "",
        role: (that.data.clsUserInfo as any).role || "",
      },
      success: (res) => {
        debugger
        let _res = res.data as any
        if (_res.code === 200) {
          that.setData({
            testTable: _res.data
          })
        } else if (_res.code === 204) {
          that.setData({
            testTable: []
          })
        } else {
          wx.showToast({
            title: _res.msg,
            icon: 'none',
            duration: 2021
          })
        }
      }
    })
  }
  // ==================== 用户自定义方法  end  =================== //
})
